#include "type.h"
#include "const.h"
#include "protectmode.h"
#include "prototype.h"
#include "string.h"
#include "global.h"



//给出选择子，取得段的物理地址
PUBLIC int32 seg2phys(int16 seg)
{
	DESCRIPTOR* p_dest = &gdt[seg >> 3];
	return (p_dest->base_high << 24) | (p_dest->base_mid << 16) | (p_dest->base_low);
}


//初始化描述符函数
PUBLIC void init_descriptor(DESCRIPTOR * p_desc, int32 base, int32 limit, int16 attribute)
{
	p_desc->limit_low		= limit & 0x0FFFF;		// limit1 2 bytes
	p_desc->base_low		= base & 0x0FFFF;		// base1 2 bytes
	p_desc->base_mid		= (base >> 16) & 0x0FF;		// base2 1 byte
	p_desc->attr1			= attribute & 0xFF;		//attibute1 1byte
	p_desc->limit_high_attr2	= ((limit >> 16) & 0x0F) |
						(attribute >> 8) & 0xF0;// limit2 + attibute 2
	p_desc->base_high		= (base >> 24) & 0x0FF;		// base3 1byte
}
